package com.woniuxy.microgoodsserver.auctionmag.mapper;

import com.woniuxy.microgoodsserver.bean.GoodsBrandBean;
import com.woniuxy.microgoodsserver.bean.GoodsSortBean;
import com.woniuxy.microgoodsserver.bean.GoodsUnitBean;
import com.woniuxy.microgoodsserver.bean.PageRequest;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface GoodsUnitMapper {

    //商品单位通过id查询
    @Select("select id,unit_numble as unitNumble,unit_name as unitName from t_goods_unit_info where id = #{id} and del_status=0")
    GoodsUnitBean unitFindAllById(@Param("id")int id);

    //商品单位分页查询
    List<GoodsUnitBean> unitFindAll(@Param("p") PageRequest request, @Param("u")GoodsUnitBean goodsUnitBean);



    //单位增加
    @Options(useGeneratedKeys = true,keyProperty = "u.id")
    @Insert("insert into t_goods_unit_info " +
            "(unit_name,unit_numble,del_status)" +
            " values(#{u.unitName},#{u.unitNumble},'0')")
    int SaveUnit(@Param("u") GoodsUnitBean goodsUnitBean);


    //单位修改
    @Update("<script>" +
            "update t_goods_unit_info" +
            "<set>" +
            "<if test='u.unitName != null'>" +
            " unit_name = #{u.unitName}," +
            "</if>" +
            "<if test='u.unitNumble != null'>" +
            " unit_numble = #{u.unitNumble}," +
            "</if>" +
            "</set>" +
            "where id = #{u.id}" +
            "</script>")
    int updateGoodUnitBean(@Param("u") GoodsUnitBean goodsUnitBean);

    //单位删除
    @Update("<script>" +
            "update t_goods_unit_info" +
            "<set>" +
            " del_status = '1'" +
            "</set>" +
            "where id = #{u.id}" +
            "</script>")
    int delGoodUnitBean(@Param("u") GoodsUnitBean goodsUnitBean);
}
